/*
create Time 2016/5/9 上午8:46:35
自定义工具类库
依赖类库 JQ
@author wyd

*/

/* 模态框*/


(function(window){
	var teststr="<div class='modal fade  in' style='display: block;' class='myTool-myModal'>"+
	"			  <div class='modal-dialog' style='width: 300px;'> "+
	"			    <div class='modal-content'>"+
	"			      <div class='modal-header'>"+
	"			        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>"+
	"			        <h4 class='modal-title' id='myTool-modal-Title'>是否提交</h4>"+
	"			      </div>"+
	"			      <div class='modal-body'>"+
	"			        <p id='myTool-content-text'>您确认要提交这份信息？&hellip;</p>"+
	"			      </div>"+
	"			      <div class='modal-footer'>"+
	"			        <button type='button'  id='myTool-cancle'class='btn btn-default' data-dismiss='modal'>取消</button>"+
	"			        <button type='button' id='myTool-sure' class='btn btn-primary'>确认</button>"+
	"			      </div>"+
	"			    </div>"+
	"			  </div>"+
	"			</div>";
	var myTool={};
	myTool.modal={};
	myTool.modal.base=function(modalobj){		
			if(modalobj.isDestroy==null){
				modalobj.isDestroy=false;
			}			
			var div=document.createElement("div");			
			$(div).append(modalobj.modalElement);			
			$(div).attr("class","myTool-modal-container container-fuild");
			$("body").append(div);
			$(div).hide();
			$(div).find(modalobj.selectTitle).text(modalobj.title);;
			$(div).find(modalobj.selectContext).text(modalobj.context);;
			$(div).find(modalobj.selectorOk).click(modalobj.callback);
			$(div).find(modalobj.selectorCancle).click(function(){				
				if(modalobj.isMask){
					$(div).modal("hide");								
				}else{
					$(div).hide();			
				}
			});
			$(div).find(modalobj.selectorOk).click(function(){
				if(modalobj.isMask){
					$(div).modal("hide");							
				}else{
					$(div).hide();				
				}
			});
			if(modalobj.trgger!=null){			
				$(document).on("click",modalobj.trgger,function(){
					if(modalobj.isMask){
						$(div).modal("show");							
					}else{
						$(div).show();				
					}
									
				});
			}else{
				if(modalobj.isMask){
					$(div).modal("show");							
				}else{
					$(div).show();				
				}
			}
	}
	
	myTool.alert=function(alertObj){		
		myTool.modal.base({
			trgger:alertObj.trgger,
			modalElement:teststr,
			selectorOk:"#myTool-sure",
			context:alertObj.context,
			selectorCancle:"#myTool-cancle",
			selectContext:"#myTool-content-text",
			selectTitle:"#myTool-modal-Title",
			title:alertObj.title,
			callback:alertObj.callback,
			isMask:alertObj.isMask,
			isDestroy:false 		
		});	
	}

	myTool.createElement=function(name){
		return document.createElement(name);	
	}
	window.myTool=myTool;
})(window)


 